//
// Created by wangyihu2020 on 2022/6/7.
//
#pragma once
#include <CSC_Matrix.h>
#include <iostream>
#include <window.h>


CSC_Matrix::CSC_Matrix(const qp_float* src, qp_int row, qp_int col) {
    m_type = CSC_MATRIX;
    m_maxElm = -1.7e38;
    m_dataSize = 0;
    m_colSize = col;
    m_rowSize = row;

    m_row = (qp_int*)calloc(m_maxSize, sizeof(qp_int));
    m_col = (qp_int*)malloc(sizeof(qp_int) * (col + 1) );
    m_data = (qp_float*)calloc(m_maxSize, sizeof(qp_float));

    m_col[0] = 0;
    qp_int count = 0;
    for(int j = 0; j < col; j++){
        for(int i = 0; i < row; i++){
            qp_float elm = src[i * col + j];
            if(elm < m_threshold && elm > -m_threshold) continue;
            else {
                m_maxElm = m_maxElm > elm ? m_maxElm : elm;
                m_data[count] = elm;
                m_row[count++] = i;
                m_dataSize++;
            }
        }
        m_col[j + 1] = count;
    }
//    m_col[col] = m_dataSize - 1;
}


CSC_Matrix::CSC_Matrix(qp_int row, qp_int col) {
    m_type = CSC_MATRIX;
    m_maxElm = -1.7e38;
    m_dataSize = 0;
    m_colSize = col;
    m_rowSize = row;
    m_row = (qp_int*)calloc(m_maxSize, sizeof(qp_int));
    m_col = (qp_int*)malloc(sizeof(qp_int) * (col + 1) );
    m_data = (qp_float*)calloc(m_maxSize, sizeof(qp_float));
}


void CSC_Matrix::printRow() const {
    std::cout<<"Row array( size: "<<m_dataSize << ") :"<<std::endl;
    for(int i = 0; i < m_dataSize; i++){
        std::cout<<m_row[i]<<' ';
//        if(i % 10 == 9) std::cout<<std::endl;
    }
    std::cout<<std::endl;
}

void CSC_Matrix::printCol() const {
    std::cout<<"Col array( size: "<<m_colSize << ") :"<<std::endl;
    for(int i = 0; i < m_colSize + 1; i++){
        std::cout<<m_col[i]<<' ';
//        if(i % 10 == 9) std::cout<<std::endl;
    }
    std::cout<<std::endl;
}









